#ifndef NOPTHREAD
#include "Thread.h"
#include "stdio.h"
Thread::Thread() {
	busy = false;
}

Thread::~Thread() {

}

/* static */
void *Thread::entryPoint(void *pthis) {
        Thread *ptr = static_cast<Thread *>(pthis);
        ptr->run();
}

void Thread::Start() {
        int nRet;
        //busy = true;
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

		if (nRet = pthread_create(&m_threadId, &attr, entryPoint, this) != 0) {
				// throw an error
			printf("ERROR; return code from pthread_join() is %d\n", nRet);
		}
        pthread_attr_destroy(&attr);
}

void Thread::Wait() {
		int rc;
		//if(busy){
			if (rc=pthread_join(m_threadId, NULL) != 0) {
					// throw an error
				printf("ERROR; return code from pthread_join() is %d\n", rc);
			}
		//}
}

void Thread::Abort() {
        if (pthread_cancel(m_threadId) != 0) {
                // throw an error
        }
}

void Thread::Detach() {
        if (pthread_detach(m_threadId) != 0) {
                // throw an error
        }
}

pthread_t Thread::GetId() {
        return m_threadId;
}
#endif
